<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8">
        <title>实名认证</title>
        <link rel="stylesheet" href="/app/admin/component/layui/css/layui.css?v=2.8.12" />
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
    </head>
    <body class="pear-container">
        <style>
            .layui-input-block input {
                width: 300px;
            }
        </style>

        <div class="layui-card">
            <div class="layui-card-body">

                <?php if ($config['ident']['ident_type'] == 1): ?>

                <form class="layui-form">

                    <blockquote class="layui-elem-quote" style="color: red; font-weight: bold;"><?=$config['ident']['ident_content']?></blockquote>

                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" name="" autocomplete="off" class="layui-input" value="<?=$admin['username']?>" disabled>
                        </div>
                    </div>

                    <?php if ($admin['ident_type'] > 0): ?>
                    <div class="layui-form-item">
                        <label class="layui-form-label">手机号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="" autocomplete="off" class="layui-input" value="<?=$admin['ident_mobile']?>" disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">真实姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="" required  lay-verify="required" placeholder="请输入用户姓名" autocomplete="off" class="layui-input" value="<?=$admin['truename']?>" disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">身份证号</label>
                        <div class="layui-input-block">
                            <input type="text" name="" required  lay-verify="required" placeholder="请输入身份证号" autocomplete="off" class="layui-input" value="<?=$admin['id_number']?>" disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="pear-btn pear-btn-primary pear-btn-md" >
                                已认证
                            </button>
                        </div>
                    </div>
                    <?php else: ?>
                    <div class="layui-form-item">
                        <label class="layui-form-label">手机号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="ident_mobile" autocomplete="off" class="layui-input" value="<?=$admin['ident_mobile']?>">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">真实姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="truename" required  lay-verify="required" placeholder="请输入用户姓名" autocomplete="off" class="layui-input" value="<?=$admin['truename']?>">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">身份证号</label>
                        <div class="layui-input-block">
                            <input type="text" name="id_number" required  lay-verify="required" placeholder="请输入身份证号" autocomplete="off" class="layui-input" value="<?=$admin['id_number']?>">
                        </div>
                    </div>

                    <input type="hidden" name="ident_type" value="<?=$config['ident']['ident_type']?>">
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="save">
                                提交
                            </button>
                            <button type="reset" class="pear-btn pear-btn-md">
                                重置
                            </button>
                            <button type="button" class="pear-btn pear-btn-danger pear-btn-md logout" lay-on="logout">
                                注销登录
                            </button>
                        </div>
                    </div>
                    <?php endif; ?>

                </form>

                <?php else: ?>
                <p>实名认证未对接</p>
                <?php endif; ?>

            </div>
        </div>


        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script>

            // 相关接口
            const API = "/app/admin/account/ident";

            layui.use(["form", "popup"], function () {
                let form = layui.form;
                let $ = layui.$;
                var util = layui.util;
                var popup = layui.popup;

                form.on("submit(save)", function(data){
                    $.ajax({
                        url: API,
                        dataType: "json",
                        type: "POST",
                        data: data.field,
                        success: function (res) {
                            if (res.code) {
                                return layui.popup.failure(res.msg);
                            }

                            layui.popup.success(res.msg);
                            setTimeout(function(){
                                // location.reload(true);
                                window.location.href = "/app/admin";
                            },1500);
                            return true;
                        }
                    });
                    return false;
                });

                // 普通事件
                util.on('lay-on', {
                    // 注销登录
                    "logout": function(othis){
                        $.ajax({
                            url: "/app/admin/account/logout",
                            dataType: "json",
                            success: function (res) {
                                if (res.code) {
                                    return popup.error(res.msg);
                                }
                                // popup.success("注销成功",function(){
                                //     location.reload();
                                // })
                                if(res.data.user_status == 1){
                                    popup.success("注销成功",function(){
                                        location.reload();
                                    })
                                }
                                if(res.data.user_status != 1){
                                    popup.success("注销成功！",function(){
                                        window.location.href="/app/user/";
                                    })
                                }
                            }
                        });
                    }
                });

            });

        </script>

    </body>
</html>
